package com.baizhi.service.impl;

import com.baizhi.dao.CityDao;
import com.baizhi.entity.City;
import com.baizhi.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class CityServiceImpl implements CityService {

    @Autowired
    private CityDao cityDao;

    // 查询所有城市
    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<City> findAll() {
        return cityDao.findAll();
    }

    @Override
    public void updateCity(City city) {
        cityDao.update(city);
    }

    @Override
    public void save(City city) {
        // 处理录入时间
        city.setCreatetime(new Date());

        // 处理当前人数
        city.setNumbers(0);
        cityDao.save(city);
    }

}
